import osg2

def getFcName(fc,def_name=""):
   """ return a name from a field container. """
   name = def_name
   if hasattr(fc,"getName") and (type(fc) not in [osg2.Image,]):
      return fc.getName()
   
   try:
      name = osg2.getName(fc)
      if not name:
         name = def_name
   except:
      pass 
   
   return name


def setFcName(fc,name):
   """ Attempt to set the name of a field container. """   
   if hasattr(fc,"setName") and (type(fc) not in [osg2.Image,]):
      return fc.setName(name)
   
   try:
      osg2.setName(fc, name)      
   except:
      pass    




def getDerivedTypes(baseType):
   """ Given an osg2 class type, find all types in the system
       That are polymorphical substitutible.
       Note: This includes the base type in the returned list.
   """  
   ret_type = [c for c in osg2.__dict__.itervalues() if isinstance(c,type) \
                and (baseType in c.__mro__) and not c.__name__.endswith("Base")]
   
   return ret_type

